package hot;

public class Num5 {
    public static void main(String[] args) {
        Num5 num5 = new Num5();
        System.out.println(num5.longestPalindrome("babad"));
    }
    public String longestPalindrome(String s) {
        int n = 0;
        int len = s.length();
        String ans = "";
        for (int i = 0; i < len; i++) {
            for (int j = i; j <= len; j++) {
                if (isHW(s,i,j) && (j - i + 1) > n) {
                    n = j - i + 1;
                    ans = s.substring(i,j);
                }
            }
        }
        return ans;
    }

    boolean isHW(String s,int i,int j) {
        while (i < j) {
            if (s.charAt(i) != s.charAt(j)) return false;
            i++;
            j--;
        }
        return true;
    }
}
